home *** CD-ROM | disk | FTP | other *** search
-
- /*© Copyright 1988-1992 UserLand Software, Inc. All Rights Reserved.*/
-
- #include "iacinternal.h"
-
-
- /*
- 8/24/92 DW: The routines in this file are usually only needed in double-
- clickable applications.
- */
-
-
- OSErr IACdrivefilelist (tyFScallback handlespecroutine) {
-
- /*
- the opendoc and printdoc required events take a list of filespecs as a
- parameter. we factor out the common code, and make it a little easier for an
- application to handle these events.
-
- you supply a callback routine that handles a single filespec, you could
- print it or open it, depending on which of the required events is being
- invoked.
- */
-
- AEDesc desc;
- long ctfiles;
- DescType actualtype;
- long actualsize;
- AEKeyword actualkeyword;
- FSSpec fs;
- long i;
- OSErr ec;
-
- ec = AEGetKeyDesc (IACglobals.event, keyDirectObject, typeAEList, &desc);
-
- IACglobals.errorcode = ec;
-
- if (ec != noErr)
- return (ec);
-
- ec = AECountItems (&desc, &ctfiles);
-
- IACglobals.errorcode = ec;
-
- if (ec != noErr)
- return (ec);
-
- for (i = 1; i <= ctfiles; i ++) {
-
- ec = AEGetNthPtr (
- &desc, i, typeFSS, &actualkeyword, &actualtype,
-
- (Ptr) &fs, sizeof (fs), &actualsize);
-
- IACglobals.errorcode = ec;
-
- if (ec != noErr) {
-
- AEDisposeDesc (&desc);
-
- return (ec);
- }
-
- if (!(*handlespecroutine) (&fs))
- return (-1);
- } /*for*/
-
- return (noErr);
- } /*IACdrivefilelist*/
-
-
- static OSType IACgetprocesscreator (void) {
-
- /*
- get the 4-character creator identifier for the application we're running
- inside of.
- */
-
- ProcessSerialNumber psn;
- ProcessInfoRec info;
-
- GetCurrentProcess (&psn);
-
- info.processInfoLength = (long) sizeof (info);
-
- info.processName = nil;
-
- info.processAppSpec = nil;
-
- GetProcessInformation (&psn, &info);
-
- return (info.processSignature);
- } /*IACgetprocesscreator*/
-
-
- static pascal OSErr CoerceTargetIDToType (DescType typecode, Ptr dataptr, Size datasize, DescType totype, long refcon, AEDesc *result) {
-
- TargetID target;
- ProcessSerialNumber psn;
- ProcessInfoRec info;
- Ptr addressoftype;
- OSErr ec;
-
- BlockMove (dataptr, &target, sizeof (target));
-
- if (target.location.locationKindSelector == ppcNoLocation) { /*local program*/
-
- ec = GetProcessSerialNumberFromPortName (&target.name, &psn);
-
- if (ec != noErr)
- return (ec);
-
- info.processInfoLength = (long) sizeof (info);
-
- info.processName = nil;
-
- info.processAppSpec = nil;
-
- ec = GetProcessInformation (&psn, &info);
-
- if (ec != noErr)
- return (ec);
-
- addressoftype = (Ptr) &info.processSignature;
- }
-
- else { /*not a local program*/
-
- if (target.name.portKindSelector == ppcByCreatorAndType)
- addressoftype = (Ptr) &target.name.u.port.creator;
- else
- addressoftype = ((Ptr) &target.name.u.portTypeStr) + 1; /*kloooge*/
- }
-
- (*result).descriptorType = typeType;
-
- return (PtrToHand (addressoftype, &(*result).dataHandle, 4));
- } /*CoerceTargetIDToType*/
-
-
- static pascal OSErr CoercePSNToType (DescType typecode, Ptr dataptr, Size datasize, DescType totype, long refcon, AEDesc *result) {
-
- ProcessInfoRec info;
- OSErr ec;
-
- info.processInfoLength = (long) sizeof (info);
-
- info.processName = nil;
-
- info.processAppSpec = nil;
-
- ec = GetProcessInformation ((ProcessSerialNumber *) dataptr, &info);
-
- if (ec != noErr)
- return (ec);
-
- (*result).descriptorType = typeType;
-
- return (PtrToHand (&info.processSignature, &(*result).dataHandle, 4));
- } /*CoercePSNToType*/
-
-
- Boolean IACinit (void) {
-
- /*
- returns true if the machine we're running on has Apple events, and if we are
- able to install our coercion handlers. it may do more in future versions.
-
- call this routine before using any of the other iac.c routines. disable your
- Apple event support if we return false.
-
- 8/23/92 DW: only initialize once, no matter how many times we're called.
- */
-
- static Boolean fl = false;
-
- if (fl)
- return (true);
-
- fl = true;
-
- if (!IAChaveappleevents ())
- return (false);
-
- if (!IACinstallcoercionhandler (typeProcessSerialNumber, typeType, (ProcPtr) &CoercePSNToType))
- return (false);
-
- if (!IACinstallcoercionhandler (typeTargetID, typeType, (ProcPtr) &CoerceTargetIDToType))
- return (false);
-
- IACglobals.idprocess = IACgetprocesscreator ();
-
- IACglobals.waitroutine = nil;
-
- IACglobals.nextparamoptional = false;
-
- return (true);
- } /*IACinit*/
-
-
- Boolean IAChaveappleevents (void) {
-
- /*
- return true if Apple Events are available.
- */
-
- long gestaltAppleEventsPresent;
-
- if (Gestalt (gestaltAppleEventsAttr, &gestaltAppleEventsPresent) != noErr)
- return (false);
-
- return (gestaltAppleEventsPresent != 0);
- } /*IAChaveappleevents*/
-
-
-
-
-
-